package temp;

/**
 * @author wangxi created on 2021/6/27 17:53
 * @version v1.0
 */
public class MultiPrint {

    public static Object lock = new Object();

    private void fun01() {
        for (int i = 1; i < 100; i = i + 2) {
            synchronized (lock) {
                System.out.print(i +" ");
                lock.notify();
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    private void fun02() {
        for (int i = 2; i <= 100; i = i + 2) {
            synchronized (lock) {
                System.out.print(i + " ");
                lock.notify();
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        MultiPrint obj = new MultiPrint();
        new Thread(() -> {
            obj.fun01();
        }).start();

        Thread.sleep(100);

        new Thread(() -> {
            obj.fun02();
        }).start();
    }
}
